#include "graph_support/TestKnightWalksOnChessBoard.h"

#include <sstream>

#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>

#include "graph_support/Graph.h"
#include "graph_support/impls/vector/VectorGraph.h"
#include "graph_support/utils/test_my_graph/BoostTestUtils.h"
#include "graph_support/utils/GraphTemplateUtils.h"

#include "graph_support/fakes/ChessBoard.h"

void TestKnightsFirstStepWalking()
{
//	using namespace test_gs_fakes;
	ChessBoard chbrd( 8, 8 );
	ChessBoard::GrVertex v( 5, 5 );
	std::stringstream buf;
	for ( int i = 0; i < 7; i++ )
	{
		buf << ( i == 0 ? "" : "; " ) << boost::lexical_cast< std::string >( v );
		v = ( * chbrd.getEdgsBeg( v ) )->end();
		buf << " -> " << boost::lexical_cast< std::string >( v );
	}
	BOOST_CHECK_EQUAL(
			std::string(
				"chess-pos:<5,5> -> chess-pos:<6,7>; chess-pos:<6,7> -> chess-pos:<7,5>; " ) +
				"chess-pos:<7,5> -> chess-pos:<6,7>; chess-pos:<6,7> -> chess-pos:<7,5>; " +
				"chess-pos:<7,5> -> chess-pos:<6,7>; chess-pos:<6,7> -> chess-pos:<7,5>; " +
				"chess-pos:<7,5> -> chess-pos:<6,7>",
			buf.str() );
}

void TestAddressesOfEdgeAttributes()
{
	using namespace GRAPH_SUPPORT_NS::utils;
//	using namespace test_gs_fakes;

	ChessBoard chbrd( 8, 8 );
	boost::optional< ChessBoard::GrEdgePtr > e5576 =
			findEdge( chbrd, ChessBoard::GrVertex( 5, 5 ), ChessBoard::GrVertex( 7, 6 ) );
	BOOST_CHECK( e5576 );
	ChessBoard::EdgeAttributes * attrs0 = & ( e5576.get()->getAttributes() );
	BOOST_CHECK( attrs0 );
	boost::optional< ChessBoard::GrEdgePtr > e7664 =
			findEdge( chbrd, ChessBoard::GrVertex( 7, 6 ), ChessBoard::GrVertex( 6, 4 ) );
	BOOST_CHECK( e7664 );
	ChessBoard::EdgeAttributes * attrs1 = & ( e7664.get()->getAttributes() );
	BOOST_CHECK( attrs1 );

	BOOST_CHECK_NE( attrs0, attrs1 );
}
